package com.orion.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author Administrator
 * @date 2022/2/13
 */

@Configuration
public class CustomThreadPoolTaskExecutor {

    @Bean(name = "llcThreadPoolTaskExecutor")
    @ConditionalOnProperty(value = "async.asyncTaskWithCustomPool", havingValue = "true")
    public ThreadPoolTaskExecutor instanceCustomThreadPoolTaskExecutor(){
        ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
        threadPoolTaskExecutor.setCorePoolSize(3);
        threadPoolTaskExecutor.setKeepAliveSeconds(60 * 5);
        threadPoolTaskExecutor.setMaxPoolSize(5);
        threadPoolTaskExecutor.setQueueCapacity(16);
        threadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown(true);
        threadPoolTaskExecutor.setThreadNamePrefix("llc-execute-");
        return threadPoolTaskExecutor;
    }

}
